package com.fc.test.service;

import java.util.List;
import java.util.Arrays;

import com.fc.test.model.auto.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import cn.hutool.core.util.StrUtil;
import com.fc.test.common.base.BaseService;
import com.fc.test.common.support.ConvertUtil;
import com.fc.test.mapper.auto.EntUserMapper;
import com.fc.test.model.custom.Tablepar;
import com.fc.test.util.SnowflakeIdWorker;
import com.fc.test.util.StringUtils;

/**
 * 企业用户 EntUserService
 * @Title: EntUserService.java 
 * @Package com.fc.test.service 
 * @author DrRic_自动生成
 * @email drhyz@qq.com
 * @date 2020-07-05 17:22:10  
 **/
@Service
public class EntUserService implements BaseService<EntUser, EntUserExample>{
	@Autowired
	private EntUserMapper entUserMapper;
	
      	      	   	      	      	      	      	      	      	
	/**
	 * 分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	 public PageInfo<EntUser> list(Tablepar tablepar,EntUser record){
	        EntUserExample testExample=new EntUserExample();
	        if(record.getEid()!=null){
				testExample.createCriteria().andEidEqualTo(record.getEid());
				testExample.setOrderByClause("uid ASC");
				if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
					testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
				}
				PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
				List<EntUser> list= entUserMapper.selectByExample(testExample);
				PageInfo<EntUser> pageInfo = new PageInfo<EntUser>(list);
				return  pageInfo;
			}
	        else {
	        	return new PageInfo<>();
			}
	 }

	public PageInfo<EntUser> listForSys(Tablepar tablepar, EntUser record){
		EntUserExample testExample=new EntUserExample();
		testExample.createCriteria().andLikeQuery(record);
		testExample.setOrderByClause("uid ASC");
		if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
			testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
		}
		PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
		List<EntUser> list= entUserMapper.selectByExample(testExample);
		PageInfo<EntUser> pageInfo = new PageInfo<EntUser>(list);
		return  pageInfo;
	}

	@Override
	public int deleteByPrimaryKey(String ids) {
					
			Integer[] integers = ConvertUtil.toIntArray(",", ids);
			List<Integer> stringB = Arrays.asList(integers);
			EntUserExample example=new EntUserExample();
			example.createCriteria().andUidIn(stringB);
			return entUserMapper.deleteByExample(example);
			
				
	}
	
	
	@Override
	public EntUser selectByPrimaryKey(String id) {
				
			Integer id1 = Integer.valueOf(id);
			return entUserMapper.selectByPrimaryKey(id1);
				
	}


	//同理，此处也屏蔽了密码以防修改
	@Override
	public int updateByPrimaryKeySelective(EntUser record) {
		return entUserMapper.updateByPrimaryKeySelective(record);
	}

	public int updatePasswordByPrimaryKeySelective(String id, String password) {
		Integer id1 = Integer.valueOf(id);

		return entUserMapper.updatePasswordByPrimaryKeySelective(id1, password);
	}
	
	
	/**
	 * 添加
	 */
	@Override
	public int insertSelective(EntUser record) {
				
		record.setUid(null);
		
				
		return entUserMapper.insertSelective(record);
	}
	
	
	@Override
	public int updateByExampleSelective(EntUser record, EntUserExample example) {
		
		return entUserMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(EntUser record, EntUserExample example) {
		
		return entUserMapper.updateByExample(record, example);
	}

	@Override
	public List<EntUser> selectByExample(EntUserExample example) {
		
		return entUserMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(EntUserExample example) {
		
		return entUserMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(EntUserExample example) {
		
		return entUserMapper.deleteByExample(example);
	}
	
	/**
	 * 检查name
	 * @param entUser
	 * @return
	 */
	public int checkNameUnique(EntUser entUser){
		EntUserExample example=new EntUserExample();
		example.createCriteria().andEidEqualTo(entUser.getEid());
		List<EntUser> list=entUserMapper.selectByExample(example);
		return list.size();
	}


	public EntUser findByName(String username) {
		return  entUserMapper.selectByName(username);
	}
}
